package org.xg.study.pd;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName JDBCUtil
 * @date 2021/9/16 16:35
 **/
public class JDBCUtil {
    private static Logger logger = LoggerFactory.getLogger(JDBCUtil.class);

    public static final String URL = "jdbc:mysql://127.0.0.1:3306/cloud";
    public static final String USER = "root";
    public static final String PWD = "123456";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        Connection connection = DriverManager.getConnection(URL, USER, PWD);
        //3.操作数据库
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select id, name, age from user");
        //如果有数据，rs.next()返回true
        while (resultSet.next()) {
            logger.info("测试结果 姓名:{}, 年龄：{} ", resultSet.getString("name"), resultSet.getInt("age"));
        }
    }
}
